package reviewAlgorithms.doublePointers;

import reviewAlgorithms.ListNode.ListNode;

public class HasRing {
    public static void main(String[] args) {

    }

    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null){
            return false;
        }
        ListNode before = head;
        ListNode after = head;
        before = before.next;
        while (before != after){
            if (before.next != null){
                before = before.next;
            }else {
                return false;
            }
            if (before.next != null){
                before = before.next;
            }else {
                return false;
            }
            after = after.next;
        }
        return true;
    }
}
